package som.simon.reactor;

import reactor.core.publisher.Flux;

public class ZipWithMain {

    public static void main(String[] args) {

        // 元组  最多支持八个
        Flux.range(1, 5)
                // 组合，多余元素舍去， 根据最小个数匹配到元组中
                .zipWith(Flux.just("A", "B", "C", "D"))
                // .log()
                .subscribe(tuple -> {
                    System.out.println("tuple = " + tuple);
                    System.out.println("type = " + tuple.getClass());
                    System.out.println("tuple.getT1() = " + tuple.getT1());
                    System.out.println("tuple.getT2() = " + tuple.getT2());
                });


        /**
         * v = [1,A]
         * type = class reactor.util.function.Tuple2
         * v.getT1() = 1
         * v.getT2() = A
         *
         * v = [2,B]
         * type = class reactor.util.function.Tuple2
         * v.getT1() = 2
         * v.getT2() = B
         *
         * v = [3,C]
         * type = class reactor.util.function.Tuple2
         * v.getT1() = 3
         * v.getT2() = C
         *
         * v = [4,D]
         * type = class reactor.util.function.Tuple2
         * v.getT1() = 4
         * v.getT2() = D
         */

        Flux.zip(
                Flux.range(10, 10),
                Flux.range(20, 10),
                Flux.range(30, 10),
                Flux.range(40, 10),
                Flux.range(50, 10)
        ).subscribe(tuple -> {
            System.out.println("tuple = " + tuple);
            System.out.println("type = " + tuple.getClass());
            System.out.println("tuple.getT1() = " + tuple.getT1());
            System.out.println("tuple.getT2() = " + tuple.getT2());
            System.out.println("tuple.getT3() = " + tuple.getT3());
            System.out.println("tuple.getT4() = " + tuple.getT4());
            System.out.println("tuple.getT5() = " + tuple.getT5());
        });


    }

}
